// 记得合并
const initialState = {
  comments: {
    end_id: '',
    last_id: '',
    results: [] as CommentType[],
  },
  originComment: {} as CommentType,
};
export type CommentType = {
  aut_id: string;
  aut_name: string;
  aut_photo: string;
  com_id: string;
  content: string;
  is_followed: boolean;
  is_liking: boolean;
  like_count: number;
  pubdate: string;
  reply_count: number;
};

export type ComActionType =
  | {
      type: 'comment/saveList';
      payload: typeof initialState.comments;
    }
  | {
      type: 'comment/clearComments';
    }
  | {
      type: 'comment/saveOriginComent';
      payload: CommentType;
    }
  | { type: 'comment/clearOriginComment' };
export default function commentReducer(
  state = initialState,
  action: ComActionType
): typeof initialState {
  switch (action.type) {
    case 'comment/saveList':
      return {
        ...state,
        comments: action.payload,
      };
    case 'comment/clearComments':
      return {
        ...state,
        comments: {} as any,
      };
    case 'comment/saveOriginComent':
      return {
        ...state,
        originComment: action.payload,
      };
    case 'comment/clearOriginComment':
      return {
        ...state,
        originComment: {} as CommentType,
      };
    default:
      return state;
  }
}
